//
//  MarryGameSubViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/9/14.
//  Copyright © 2020 王洋. All rights reserved.
//
#import "XLPageViewController.h"
#import "TT_WebviewController.h"
#import "MarryGameSubViewController.h"

@interface MarryGameSubViewController ()
<XLPageViewControllerDelegate,
XLPageViewControllerDataSrouce>

@property (nonatomic, strong) XLPageViewController *pageViewController;

@property (nonatomic, strong) NSMutableArray *titleArray;
//进入控制器时间
@property(nonatomic,strong)NSString *inTime;
@end

@implementation MarryGameSubViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

    self.title = @"迎亲游戏";
    
    [self initPageViewController];
    self.inTime = [NSString stringWithFormat:@"%0.0f",[Utilities getCurrentTimestamp]];
}
- (void)dealloc
{
    NSLog(@"MarryGameSubViewController ---dealloc");
    [[StatisticManager shareManager]insertBrowseUserActiveQuantityWithToolType:@"8" WithInTime:self.inTime];
}
- (void)initPageViewController {
    
    XLPageViewControllerConfig *config = [XLPageViewControllerConfig defaultConfig];
    config.shadowLineColor = UIColorHex(0xff4242);
    config.titleSelectedFont = [UIFont boldSystemFontOfSize:14];
    config.titleNormalFont = [UIFont systemFontOfSize:14];
    config.titleViewAlignment = XLPageTitleViewAlignmentCenter;
    config.separatorLineHidden = true;
    config.shadowLineAnimationType = XLPageShadowLineAnimationTypeZoom;
    config.shadowLineWidth = 20;
    config.titleSpace = 20;
    
    self.pageViewController = [[XLPageViewController alloc] initWithConfig:config];
    self.pageViewController.view.frame = self.view.bounds;
    self.pageViewController.delegate = self;
    self.pageViewController.dataSource = self;
    [self addChildViewController:self.pageViewController];
    [self.view addSubview:self.pageViewController.view];
}

#pragma mark -
#pragma mark TableViewDelegate&DataSource
- (UIViewController *)pageViewController:(XLPageViewController *)pageViewController viewControllerForIndex:(NSInteger)index {
    
    TT_WebviewController *vc = [[TT_WebviewController alloc] init];
    
    NSInteger urlIndex = index + 1;
    NSString *htmlUrl = [NSString
                       stringWithFormat:@"%@/makeSpeech?type=%@&id=%02ld", BA_GlobalH5_Domain,@"game",(long)urlIndex];
    vc.webUrl = htmlUrl;
    
    return vc;
}

- (NSString *)pageViewController:(XLPageViewController *)pageViewController titleForIndex:(NSInteger)index {
    return self.titleArray[index];
}

- (NSMutableArray *)titleArray {
    
    if (!_titleArray) {
        _titleArray = @[@"冲破保鲜膜",@"把爱甩出来",@"基情传物",@"气球大作战",@"对你爱不完",@"众里寻她",@"找婚鞋",@"成语大全"].mutableCopy;
    }
    return _titleArray;
}

- (NSInteger)pageViewControllerNumberOfPage {
    return self.titleArray.count;
}

@end
